﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/* TODO: test
        agate
        agate_turb 0.4    
        color_map { 
            [0 color <1,0,0> ]
            [1 color <0,1,0> ]
        }
*/

namespace POVRay {
    public class ColorMapPigment : Pattern {
        //TODO: http://www.povray.org/documentation/view/3.6.0/335/

        //TODO: wave type

        //TODO: average http://www.povray.org/documentation/view/3.7.0/365/
        //TODO: crackle http://www.povray.org/documentation/view/3.7.0/372/
        //TODO: density_file http://www.povray.org/documentation/view/3.7.0/374/
        //TODO: fractal http://www.povray.org/documentation/view/3.7.0/377/
        //TODO: function http://www.povray.org/documentation/view/3.7.0/378/
        //TODO: function image? http://www.povray.org/documentation/view/3.7.0/379/
        //TODO: image pattern http://www.povray.org/documentation/view/3.7.0/383/
        //TODO: pigment pattern http://www.povray.org/documentation/view/3.7.0/388/
        //TODO: slope http://www.povray.org/documentation/view/3.7.0/393/

        protected string Type { get; set; }
        protected float? Param0 { get; set; }
        protected float? Param1 { get; set; }
        protected Vector3 Orientation { get; set; }

        public ColorMap ColorMap { get; set; }

        private ColorMapPigment() { }

        public static ColorMapPigment AgateColorMapPigment(ColorMap colorMap, float? agateTurbulence) {
            return new ColorMapPigment() { Type = "agate", ColorMap = colorMap, Param0 = agateTurbulence };
        }

        public static ColorMapPigment BoxedColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "boxed", ColorMap = colorMap };
        }

        public static ColorMapPigment BozoColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "bozo", ColorMap = colorMap };
        }

        public static ColorMapPigment BumpsColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "bumps", ColorMap = colorMap };
        }

        public static ColorMapPigment CellsColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "cells", ColorMap = colorMap };
        }

        public static ColorMapPigment CylindricalColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "cylindrical", ColorMap = colorMap };
        }

        public static ColorMapPigment DentsColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "dents", ColorMap = colorMap };
        }

        public static ColorMapPigment GradientColorMapPigment(ColorMap colorMap, Vector3 orientation) {
            return new ColorMapPigment() { Type = "gradient", ColorMap = colorMap, Orientation = orientation };
        }

        public static ColorMapPigment GraniteColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "granite", ColorMap = colorMap };
        }

        public static ColorMapPigment LeopardColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "leopard", ColorMap = colorMap };
        }

        public static ColorMapPigment MarbleColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "marble", ColorMap = colorMap };
        }

        public static ColorMapPigment OnionColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "onion", ColorMap = colorMap };
        }

        public static ColorMapPigment PlanarColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "planar", ColorMap = colorMap };
        }

        public static ColorMapPigment QuiltedColorMapPigment(ColorMap colorMap, float? control0, float? control1) {
            return new ColorMapPigment() { Type = "quilted", ColorMap = colorMap, Param0 = control0, Param1 = control1 };
        }

        public static ColorMapPigment RadialColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "radial", ColorMap = colorMap };
        }

        public static ColorMapPigment RipplesColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "ripples", ColorMap = colorMap };
        }

        public static ColorMapPigment SphericalColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "spherical", ColorMap = colorMap };
        }

        public static ColorMapPigment Spiral1ColorMapPigment(ColorMap colorMap, int numberOfArms) {
            return new ColorMapPigment() { Type = "spiral1", ColorMap = colorMap, Param0 = numberOfArms };
        }

        public static ColorMapPigment Spiral2ColorMapPigment(ColorMap colorMap, int numberOfArms) {
            return new ColorMapPigment() { Type = "spiral2", ColorMap = colorMap, Param0 = numberOfArms };
        }

        public static ColorMapPigment WavesColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "waves", ColorMap = colorMap };
        }

        public static ColorMapPigment WoodColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "wood", ColorMap = colorMap };
        }

        public static ColorMapPigment WrinklesColorMapPigment(ColorMap colorMap) {
            return new ColorMapPigment() { Type = "wrinkles", ColorMap = colorMap };
        }

        public override string ToString(int level) {
            StringBuilder sb = new StringBuilder();

            sb.Append("pigment { ");
            sb.Append(Scene.Indentation(level + 1) + Type + " ");
            if (Type.Equals("gradient")) sb.Append(Orientation.ToString());
            else if (Type.StartsWith("spiral")) sb.Append(Param0.ToString());

            if (ColorMap != null) sb.Append(Scene.Indentation(level + 1) + ColorMap.POVRayString(level + 1));

            if (Type.Equals("agate")) {
                if (Param0.HasValue) sb.Append(Scene.Indentation(level + 1) + "agate_turb " + Param0.Value.POVRayString());
            } else if (Type.Equals("quilted")) {
                if (Param0.HasValue) sb.Append(Scene.Indentation(level + 1) + "control0 " + Param0.Value.POVRayString());
                if (Param1.HasValue) sb.Append(Scene.Indentation(level + 1) + "control1 " + Param1.Value.POVRayString());
            }

            sb.Append(GeneralParameters(level + 1));
            sb.Append(Scene.Indentation(level) + "}");

            return sb.ToString();
        }
    }
}
